snapshot: Get new GArray item directly
authorTimm Bäder <tbaeder@redhat.com>
Fri, 11 Jan 2019 09:05:44 +0000 (10:05 +0100)
committerTimm Bäder <mail@baedert.org>
Fri, 11 Jan 2019 16:02:23 +0000 (17:02 +0100)
Instead of building it up ourselves, then coping it into the GArray and
then getting the last element of that array.

gtk/gtksnapshot.c

index 81e7419207d1ecb50e6b2710387d126a63b3d678..3bc18cd4e8068ad5b8755ce7a9d2e50d7cdea0cd 100644 (file)
@@ -112,17 +112,19 @@ gtk_snapshot_push_state (GtkSnapshot            *snapshot,
                          int                     translate_y,
                          GtkSnapshotCollectFunc  collect_func)
 {
-  GtkSnapshotState state = { 0, };
+  const gsize n_states = snapshot->state_stack->len;
+  GtkSnapshotState *state;
 
-  state.translate_x = translate_x;
-  state.translate_y = translate_y;
-  state.collect_func = collect_func;
-  state.start_node_index = snapshot->nodes->len;
-  state.n_nodes = 0;
+  g_array_set_size (snapshot->state_stack, n_states + 1);
+  state = &g_array_index (snapshot->state_stack, GtkSnapshotState, n_states);
 
-  g_array_append_val (snapshot->state_stack, state);
+  state->translate_x = translate_x;
+  state->translate_y = translate_y;
+  state->collect_func = collect_func;
+  state->start_node_index = snapshot->nodes->len;
+  state->n_nodes = 0;
 
-  return &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 1);
+  return state;
 }
 
 static GtkSnapshotState *